package batch.processing;

import java.sql.Connection;
import java.sql.SQLException;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.jdbc.Work;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class HibernateTest1 {

	private SessionFactory sessionFactory;
	private Session session;
	private Transaction transaction;
	
	public void testDoWork(){
		session.doWork(new Work(){
			@Override
			public void execute(Connection arg0) throws SQLException {
				System.out.println(arg0);
			}
		});
	}
	
	@Before
	public void init(){
		System.out.println("InitMethodInvoke");
		Configuration configuration = new Configuration().configure();
		StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
		sessionFactory = configuration.buildSessionFactory(serviceRegistry);
		session = sessionFactory.openSession();
		transaction = session.beginTransaction();
	}
	
	@After
	public void destroy(){
		System.out.println("DestroyMethodInvoke");
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
}
